home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_494 / bref / bref4.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  39KB  |  1,357 lines

  1. /* Name: bref4.c -- select input
  2.     This is a modification of Anders Bjerin's FileWindow routine.
  3.         Set TAB value to 3 for this listing.
  4.     Invoked from bref.c which is main().
  5. */
  6.  
  7. #include <exec/types.h>
  8. #include <exec/nodes.h>
  9. #include <exec/lists.h>
  10. #include <exec/libraries.h>
  11. #include <exec/ports.h>
  12. #include <exec/interrupts.h>
  13. #include <exec/io.h>
  14. #include <exec/memory.h>
  15. #include <libraries/dos.h>
  16. #include <libraries/dosextens.h>
  17. #include <intuition/intuition.h>
  18. #include <string.h>
  19.  
  20. /* #include "FileWindow.h" */
  21. /* Included code for  FileWindow.h */
  22.  
  23. /* What file_window() will return: */
  24. #define GO      500
  25. #define OPTION  600
  26. #define HELP     700
  27. #define CANCEL  800
  28. #define QUIT    900
  29. #define PANIC1  1001
  30. #define PANIC2  1002
  31.  
  32. /* The maximum size of the strings: */
  33. #define DRAWER_LENGTH 100 /*  100 char's incl NULL. */
  34. #define FILE_LENGTH    30 /*   30       -"-         */
  35. #define TOTAL_LENGTH  130 /*  130       -"-         */
  36.  
  37. /* THE END of FileWindow.h */
  38.  
  39. #define igncase(c) (isupper(c)? tolower(c) : (c))    /* Ignore case--sort*/
  40.  
  41. /* Declare the functions we are going to use: */
  42. USHORT FileWindow();
  43. STRPTR right_pos();
  44. APTR save_file_info();
  45. BOOL file_comp();
  46. BOOL directory();
  47. BOOL last_check();
  48. BOOL new_drawer();
  49. BOOL pick_file();
  50. void put_in();
  51. void deallocate_file_info();
  52. void change_device();
  53. void parent();
  54. void request_ok();
  55. void display_list();
  56. void connect_dir_file();
  57. void adjust_string_gadgets();
  58.  
  59. extern struct IntuitionBase *IntuitionBase;
  60.  
  61. struct Window *file_window;
  62. struct IntuiMessage *my_gadget_message;
  63.  
  64. /* Structure for memory allocate of each file/directory */
  65. struct file_info
  66. {
  67.   BYTE name[28];          /* Name of the file/directory, 27 characters. */
  68.   BOOL directory;         /* If it is a directory.                      */
  69.   struct file_info *next; /* Pointer to the next file_info structure.   */
  70. };
  71.  
  72. struct FileInfoBlock *file_info;
  73. struct FileLock *lock, *Lock();
  74.  
  75. BOOL file_lock;  /* Have we locked a file?       */
  76. BOOL more_files; /* More files in the directory? */
  77. BOOL first_file; /* First file?                  */
  78.  
  79. struct file_info *first_pointer; /* Pointing to the first structure. */
  80.  
  81. /* ********************************************************************* */
  82. /* * IntuiText structures for the requesters                           * */
  83.  
  84. struct IntuiText text_request={0,2,JAM1,15,5,NULL,NULL,NULL};
  85.  
  86. struct IntuiText ok_request={0, 2,JAM1,6, 3,NULL,"OK",NULL};
  87.  
  88. struct IntuiText option1_request={0, 2,JAM1,6, 3,NULL,NULL,NULL};
  89.  
  90. struct IntuiText option2_request={0, 2,JAM1,6, 3,NULL,NULL,NULL};
  91.  
  92. /* Values for a 4-letter box: */
  93. SHORT points4[]={0,0,  44,0,  44,14,   0,14,   0,0};
  94.  
  95. /* Values for a 6-letter box: */
  96. SHORT points6[]={0,0,  60,0,  60,14,   0,14,   0,0};
  97.  
  98. /* A border for a 4-letter box: */
  99. struct Border border_text4={0, 0,1, 2, JAM1,5,points4,NULL};
  100.  
  101. /* A border for a 6-letter box: */
  102. struct Border border_text6={0, 0,1, 2, JAM1,5,points6,NULL};
  103.  
  104. /* ********************************************************************* */
  105. /* * Information for the help gadget */
  106.  
  107. struct IntuiText text_help = {3,0,JAM1,7,4,NULL,"HELP",NULL};
  108.  
  109. struct Gadget gadget_help = {NULL,360,40,61,15,GADGHCOMP,RELVERIFY,
  110.     BOOLGADGET,&border_text4,NULL,&text_help,NULL,NULL,0,NULL};
  111.  
  112. /* ********************************************************************* */
  113. /* * Information for the option gadget */
  114.  
  115. struct IntuiText text_option = {3,0,JAM1,7,4,NULL,"OPTION",NULL};
  116.  
  117. struct Gadget gadget_option = {&gadget_help,360,20,61,15,GADGHCOMP,
  118.     RELVERIFY,BOOLGADGET,&border_text6,NULL,&text_option,NULL,NULL,0,NULL};
  119.  
  120. /*********************************************************************** */
  121. /* * Information for the proportional gadget */
  122.  
  123. struct Image image_prop;
  124.  
  125. struct PropInfo prop_info=
  126. {
  127.   AUTOKNOB| /* We want to use the auto-knob. */
  128.   FREEVERT, /* The knob should move vertically. */
  129.   0,0,      /* HorizPot, VertPot: will be initialized later. */
  130.   0,        /* HorizBody                 -"-                 */
  131.   0xFFFF,   /* VertBody: No data to show, maximum. */
  132.   
  133.   0,0,0,0,0,0 /* Intuition sets and maintains these variables. */
  134. };
  135.  
  136. struct Gadget gadget_proportional={&gadget_option,290, 50, 21, 72,GADGHCOMP,
  137.   GADGIMMEDIATE|FOLLOWMOUSE|RELVERIFY, /* Activation */
  138.   PROPGADGET,               /* GadgetType */
  139.   (APTR) &image_prop,       /* GadgetRender */
  140.   NULL,NULL,NULL,(APTR) &prop_info,NULL,NULL };
  141.  
  142. UBYTE name_backup[DRAWER_LENGTH];    /* String Gadgets Undo Buffer */
  143.  
  144. /* ********************************************************************* */
  145. /* * Information for the string gadget "Drawer:"                       * */
  146.  
  147. UBYTE drawer_name[DRAWER_LENGTH];
  148.  
  149. /* Values for a 28-letter string box: */
  150. SHORT points28s[]={-7,-4,  200,-4,  200,11,   -7,11,   -7,-4};
  151.  
  152. /* A border for a 28-letter string box: */
  153. struct Border border_text28s={0, 0,1, 2, JAM1,5,points28s,NULL};
  154.  
  155. struct IntuiText text_drawer={1, 2,JAM1,-69, 0,NULL,"Drawer:",NULL};
  156.  
  157. struct StringInfo string_drawer={drawer_name,name_backup,0,70,0,
  158.   0,0, 0,NULL,NULL,NULL,};
  159.  
  160. struct Gadget gadget_drawer=
  161. { &gadget_proportional,83, 35, 198, 8,
  162.   GADGHCOMP,  RELVERIFY,  STRGADGET,(APTR) &border_text28s,
  163.   NULL,&text_drawer,NULL,(APTR) &string_drawer,NULL,NULL};
  164.  
  165. /* ********************************************************************* */
  166. /* * Information for the string gadget "File:"                         * */
  167.  
  168. UBYTE file_name[FILE_LENGTH];
  169.  
  170. /* Values for a 30-letter string box: */
  171. SHORT points30s[]={-7,-4,  244,-4,  244,11,   -7,11,   -7,-4};
  172.  
  173. /* A border for a 30-letter string box: */
  174. struct Border border_text30s={0, 0,1, 2, JAM1,5,points30s,NULL};
  175.  
  176. struct IntuiText text_file={1, 2,JAM1,-53, 0,NULL,"File:",NULL};
  177.  
  178. struct StringInfo string_file={file_name,name_backup,0,40,0,
  179.   0,0, 0,NULL,NULL,NULL,};
  180.  
  181. struct Gadget gadget_file={&gadget_drawer,66, 129, 240, 8,GADGHCOMP,
  182.   RELVERIFY,STRGADGET,(APTR) &border_text30s,
  183.   NULL,&text_file,NULL,(APTR) &string_file,NULL,NULL};
  184.  
  185. /* ********************************************************************* */
  186. /* * Information for the string gadget "Extension"                     * */
  187.  
  188. UBYTE extension_name[7]; /* 7 characters including NULL. */
  189.  
  190. /* Values for a 6-letter string box: */
  191. SHORT points6s[]={-7,-4,  57,-4,  57,10,  -7,10,  -7,-4};
  192.  
  193. /* A border for a 6-letter string box: */
  194. struct Border border_text6s={0,0,1,2,JAM1,5,points6s,NULL};
  195.  
  196. struct IntuiText text_extension={1, 2,JAM1,-45, 0,NULL,"Ext:",NULL};
  197.  
  198. struct StringInfo string_extension={extension_name,name_backup,0,7,0,
  199.   0,0, 0,NULL,NULL,NULL,};
  200.  
  201. struct Gadget gadget_extension=
  202.   {&gadget_file,263, 17, 59, 8,GADGHCOMP,RELVERIFY,STRGADGET,
  203.   (APTR) &border_text6s,NULL,
  204.   &text_extension,NULL,(APTR) &string_extension,NULL,NULL};
  205.  
  206. /* ********************************************************************* */
  207. /* * Information for the boolean gadget parent "<"                     * */
  208.  
  209. /* Values for a 1-letter box: */
  210. SHORT points1[]={0,0,  20,0,  20,15,   0,15,   0,0};
  211.  
  212. /* A border for a 1-letter box: */
  213. struct Border border_text1={0, 0,1, 2, JAM1,5,points1,NULL};
  214.  
  215. struct IntuiText text_parent={1, 2,JAM1,7,4,NULL,"<",NULL};
  216.  
  217. struct Gadget gadget_parent=
  218.  {&gadget_extension,290, 31, 21, 16,
  219.   GADGHCOMP,RELVERIFY,BOOLGADGET,(APTR) &border_text1,
  220.   NULL,&text_parent,NULL,NULL,NULL,NULL};
  221.  
  222. /* ********************************************************************* */
  223. /* * Information for the boolean gadget "ram:"                         * */
  224.  
  225. struct IntuiText text_ram={1, 2,JAM1,7,4,NULL,"ram:",NULL};
  226.  
  227. struct Gadget gadget_ram={&gadget_parent,161, 13, 45, 15,
  228.   GADGHCOMP,RELVERIFY,BOOLGADGET,(APTR) &border_text4,
  229.   NULL,&text_ram,NULL,NULL,NULL,NULL};
  230.  
  231. /* ********************************************************************* */
  232. /* * Information for the boolean gadget "dh0:"                         * */
  233.  
  234. struct IntuiText text_dh0={1, 2,JAM1,7,4,NULL,"dh0:",NULL};
  235.  
  236. struct Gadget gadget_dh0={&gadget_ram,110, 13, 45, 15,
  237.   GADGHCOMP,RELVERIFY,BOOLGADGET,(APTR) &border_text4,
  238.   NULL,&text_dh0,NULL,NULL,NULL,NULL};
  239.  
  240. /* ********************************************************************* */
  241. /* * Information for the boolean gadget "df1:"                         * */
  242.  
  243. struct IntuiText text_df1={1, 2,JAM1,7,4,NULL,"df1:",NULL};
  244.  
  245. struct Gadget gadget_df1={&gadget_dh0,59, 13, 45, 15,
  246.   GADGHCOMP,RELVERIFY,BOOLGADGET,(APTR) &border_text4,
  247.   NULL,&text_df1,NULL,NULL,NULL,NULL};
  248.  
  249. /* ********************************************************************* */
  250. /* * Information for the boolean gadget "df0:"                         * */
  251.  
  252. struct IntuiText text_df0={1, 2,JAM1,7,4,NULL,"df0:",NULL};
  253.  
  254. struct Gadget gadget_df0={&gadget_df1,8, 13, 45, 15,
  255.   GADGHCOMP,RELVERIFY,BOOLGADGET,(APTR) &border_text4,
  256.   NULL,&text_df0,NULL,NULL,NULL,NULL};
  257.  
  258. /* ********************************************************************* */
  259. /* * Information for the boolean gadget "CANCEL"                       * */
  260.  
  261. struct IntuiText text_cancel={3, 2,JAM1,7,4,NULL,"CANCEL",NULL};
  262.  
  263. struct Gadget gadget_cancel={&gadget_df0,360, 144, 61, 15,
  264.   GADGHCOMP,RELVERIFY,BOOLGADGET,(APTR) &border_text6,
  265.   NULL,&text_cancel,NULL,NULL,NULL,NULL};
  266.  
  267. /* ********************************************************************* */
  268. /* * Information for the boolean gadget "GO"                         * */
  269.  
  270. struct IntuiText text_input={3, 2,JAM1,7,4,NULL,"GO",NULL};
  271.  
  272. struct Gadget gadget_input={&gadget_cancel,8, 144, 61, 15,
  273.   GADGHCOMP,RELVERIFY,BOOLGADGET,(APTR) &border_text4,
  274.   NULL,&text_input,NULL,NULL,NULL,NULL};
  275.  
  276. UBYTE display_text[8][34];
  277.  
  278. struct IntuiText text_list[8]=
  279. {
  280.   {1, 0,JAM2,0,0,NULL,display_text[0],&text_list[1]},
  281.  
  282.   {1, 0,JAM2,0,8,NULL,display_text[1],&text_list[2]},
  283.  
  284.   {1, 0,JAM2,0,16,NULL,display_text[2],&text_list[3]},
  285.  
  286.   {1, 0,JAM2,0,24,NULL,display_text[3],&text_list[4]},
  287.  
  288.   {1, 0,JAM2,0,32,NULL,display_text[4],&text_list[5]},
  289.  
  290.   {1, 0,JAM2,0,40,NULL,display_text[5],&text_list[6]},
  291.  
  292.   {1, 0,JAM2,0,48,NULL,display_text[6],&text_list[7]},
  293.  
  294.   {1, 0,JAM2,0,56,NULL,display_text[7],NULL}
  295. };
  296.  
  297. struct Gadget gadget_display[8]=
  298. {
  299.   {&gadget_display[1],8, 50, 276, 12,GADGHNONE,GADGIMMEDIATE,
  300.     BOOLGADGET,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  301.  
  302.   {&gadget_display[2],8, 62, 276, 8,GADGHNONE,GADGIMMEDIATE,
  303.     BOOLGADGET,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  304.  
  305.   {&gadget_display[3],8, 70, 276, 8,GADGHNONE,GADGIMMEDIATE,
  306.     BOOLGADGET,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  307.  
  308.   {&gadget_display[4],8, 78, 276, 8,GADGHNONE,GADGIMMEDIATE,
  309.     BOOLGADGET,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  310.  
  311.   {&gadget_display[5],8, 86, 276, 8,GADGHNONE,GADGIMMEDIATE,
  312.     BOOLGADGET,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  313.  
  314.   {&gadget_display[6],8, 94, 276, 8,GADGHNONE,GADGIMMEDIATE,
  315.     BOOLGADGET,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  316.  
  317.   {&gadget_display[7],8, 102, 276, 8,GADGHNONE,GADGIMMEDIATE,
  318.     BOOLGADGET,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  319.  
  320.   {&gadget_input,8, 110, 276, 12,GADGHNONE,GADGIMMEDIATE,
  321.     BOOLGADGET,NULL,NULL,NULL,NULL,NULL,NULL,NULL}
  322. };
  323.  
  324. /* ********************************************************************* */
  325. /* * BIG BOX                                                           * */
  326.  
  327. /* Values for a big box: */
  328. SHORT points_big_box[]={8,50,  283,50,  283,121,   8,121,   8,50};
  329.  
  330. /* A border for a 1-letter box: */
  331. struct Border border_big_box={0, 0,1, 2, JAM1,5,points_big_box,NULL};
  332.  
  333. /* ********************************************************************* */
  334. /* * Information for the window                                          */
  335.  
  336. struct NewWindow new_file_window={0,0,480, 163,0,1,
  337.   CLOSEWINDOW|  GADGETDOWN|  MOUSEMOVE|  GADGETUP,
  338.   ACTIVATE|  WINDOWDEPTH|  WINDOWDRAG|  WINDOWCLOSE|  SMART_REFRESH,
  339.   &gadget_display[0],NULL,NULL,NULL,NULL,0,0,0,0,WBENCHSCREEN};
  340.  
  341.  
  342.  
  343. /* ******************************************************************* */
  344.             /* Entry point */
  345.  
  346. USHORT FileWindow(total_file_name )
  347. STRPTR total_file_name;
  348. {
  349. STRPTR extension = "";
  350. SHORT  x=0,y=0;
  351.   int temp1; /* Variable used for loops etc. */
  352.   int file_count; /* How many files/directories there are. */
  353.  
  354.   ULONG class;  /* Saved IntuiMessage: IDCMP flags. */
  355.   USHORT code;  /*        -"-        : Special code. */
  356.   APTR address; /*        -"-        : The address of the object. */
  357.  
  358.   int position; /* The number of the first file in the display. */
  359.  
  360.   BOOL working;     /* Wants the user to quit? */
  361.   BOOL fix_display; /* Should we update the file-display? */
  362.  
  363.   STRPTR string_pointer; /* Pointer to a string. */
  364.   struct file_info *pointer; /* Pointer to a file_info structure. */
  365.  
  366.   USHORT operation; /* What operation FileWindow will return. */
  367.   
  368.  
  369.   file_lock=FALSE; /* We have not locked any file/directory. */
  370.   more_files=FALSE; /* Do not list any files yet. */
  371.  
  372.  
  373.   /* Make sure the proportional gadget is at the top, showing 100%: */
  374.   prop_info.VertBody=0xFFFF;
  375.   prop_info.HorizBody=0;
  376.   prop_info.VertPot=0;
  377.   prop_info.HorizPot=0;
  378.   
  379.  
  380.   /* Copy the extension into the string gadget: */
  381.   strcpy(extension_name, extension);
  382.  
  383.   /* If there is an extension, the text "Ext:" will be highlighted: */
  384.   if(*extension_name != '\0')
  385.     text_extension.FrontPen=3; /* Orange. (Normal WB colour) */
  386.   else
  387.     text_extension.FrontPen=1; /* White. (Normal WB colour) */
  388.  
  389.  
  390.   /* Change some values in the new_file_window structure: */
  391.   new_file_window.LeftEdge=x;
  392.   new_file_window.TopEdge=y;
  393.   new_file_window.Title= "BREF FileWindow";
  394.  
  395.   /* Open the window: */
  396.   if( (file_window = (struct Window *) OpenWindow(&new_file_window)) == NULL )
  397.   {
  398.     /* We could NOT open the window! */
  399.     return(PANIC1);    /* No msg here; BREF will give error msg */
  400.   }
  401.  
  402.   /* Draw the big box around the display: */
  403.   DrawBorder(file_window->RPort, &border_big_box, 0, 0);
  404.  
  405.   /* Allocate memory for the FileInfoBlock: */
  406.   if((file_info=(struct FileInfoBlock *)
  407.     AllocMem(sizeof(struct FileInfoBlock), MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  408.   {
  409.     /* Could not allocate memory for the FileInfoBlock! */
  410.     request_ok("FileWindow--NOT enough memory!");
  411.     return(PANIC2);    /* Since msg given here, no msg in BREF */
  412.   }
  413.  
  414.   /* Anything in total_file_name? */
  415.   if(*total_file_name != '\0')
  416.   {
  417.     /* Yes--Try to "lock" the file/directory: */
  418.     if((lock=Lock(total_file_name, ACCESS_READ))==NULL)
  419.     {
  420.       /* PROBLEMS! */
  421.       /* File/directory/device did NOT exist! */
  422.     }
  423.     else
  424.     {
  425.       /* Could lock the file/directory! */
  426.       file_lock=TRUE;
  427.   
  428.       /* Get some information of the file/directory: */
  429.       if((Examine(lock, file_info))==NULL)
  430.       {
  431.         /* Could NOT examine the object! */
  432.         request_ok("FileWindow--ERROR reading file/directory!");
  433.       }
  434.       else
  435.       {
  436.         /* Is it a directory or a file? */
  437.         if(directory(file_info))
  438.         {
  439.           /* It is a directory! */
  440.  
  441.           *file_name='\0'; /* Clear file_name string. */
  442.           /* Copy total_file_name into drawer_name string: */
  443.           strcpy(drawer_name, total_file_name);
  444.  
  445.           /* Since it is a directory, we will look for more files: */
  446.           more_files=TRUE;
  447.         }
  448.         else
  449.         {
  450.           /* File--Separate the file name from the path: */
  451.           if(string_pointer=right_pos(total_file_name, '/'))
  452.           {
  453.             /* Copy the file name into file_name string: */
  454.             strcpy(file_name, string_pointer+1);
  455.             *string_pointer='\0';
  456.           }
  457.           else
  458.           {
  459.             if(string_pointer=right_pos(total_file_name, ':'))
  460.             {
  461.               /* Copy the file name into file_name string: */
  462.               strcpy(file_name, string_pointer+1);
  463.               *(string_pointer+1)='\0';
  464.             }
  465.             else
  466.             {
  467.               strcpy(file_name, total_file_name);        
  468.               *drawer_name='\0';
  469.               *total_file_name='\0';
  470.             }
  471.           }
  472.           strcpy(drawer_name, total_file_name);
  473.  
  474.           /* Since it is a file, we will NOT look for more files: */
  475.  
  476.         } /* Is it a directory? */
  477.  
  478.       } /* Could we examine the object? */
  479.  
  480.     } /* Could we "lock" the file/directory? */
  481.  
  482.   } /* Anything in the total_file_name string? */
  483.  
  484.   /* Adjust the string gadgets */
  485.   adjust_string_gadgets();
  486.  
  487.   new_drawer(); /* Start to show us the files. */
  488.  
  489.   position=0;        /* The display will show the first file. */
  490.   fix_display=FALSE; /* We do not need to fix the display. */
  491.   first_file=TRUE;   /* No files saved. */
  492.   file_count=0;      /* No files saved. */
  493.  
  494.   working=TRUE;
  495.   do
  496.   {
  497.     /* If all files shown, put task to sleep */
  498.     if(more_files==FALSE)
  499.       Wait(1 << file_window->UserPort->mp_SigBit);
  500.  
  501.     /* Any gadget activity? */
  502.     while(my_gadget_message = (struct IntuiMessage *)
  503.       GetMsg(file_window->UserPort))
  504.     {
  505.       /* Stay in loop while mouse moving.  Update display when mouse stops*/
  506.       class = my_gadget_message->Class;
  507.       code = my_gadget_message->Code;
  508.       address = my_gadget_message->IAddress;
  509.  
  510.       ReplyMsg((struct Message *)my_gadget_message);
  511.  
  512.       switch(class)
  513.       {
  514.         case MOUSEMOVE:
  515.           /* Proportional gadget selected, & mouse is moving. */ 
  516.           /* Update file_display when mouse stops. */
  517.           fix_display=TRUE;
  518.           break;
  519.  
  520.         case CLOSEWINDOW:    /* User wants to quit. */
  521.           connect_dir_file(total_file_name);
  522.           working=FALSE;
  523.           operation=QUIT;
  524.           break;
  525.  
  526.         case GADGETDOWN:    /* Gadget selected -- which one? */
  527.            /* File Display */
  528.            for(temp1=0; temp1 < 8; temp1++)
  529.            {
  530.              if(address == (APTR)&gadget_display[temp1])
  531.              {
  532.                /* The user wants to select a file/directory: */
  533.                pick_file(temp1+position);
  534.              }
  535.            }
  536.            break;
  537.  
  538.         case GADGETUP:    /* Gadget released -- which one? */
  539.  
  540.            if(address == (APTR)&gadget_input ||    /* GO */
  541.                   address == (APTR)&gadget_file)        /* FILE */
  542.            {
  543.              if(last_check(total_file_name))
  544.              {
  545.                working=FALSE;
  546.                operation=GO;
  547.              }
  548.              break;
  549.            }
  550.  
  551.            if(address == (APTR)&gadget_cancel)    /* CANCEL */
  552.            {
  553.              connect_dir_file(total_file_name);
  554.              working=FALSE;
  555.              operation=CANCEL;
  556.              break;
  557.            }
  558.  
  559.            if(address == (APTR)&gadget_df0)    /* df0: */
  560.            {
  561.              change_device("df0:");
  562.              break;
  563.            }
  564.  
  565.            if(address == (APTR)&gadget_df1)    /* df1: */
  566.            {
  567.              change_device("df1:");
  568.              break;
  569.            }
  570.  
  571.            if(address == (APTR)&gadget_dh0)    /* dh0: */
  572.            {
  573.              change_device("dh0:");
  574.              break;
  575.            }
  576.  
  577.            if(address == (APTR)&gadget_ram)    /* ram: */
  578.            {
  579.              change_device("ram:");
  580.              break;
  581.            }
  582.  
  583.            if(address == (APTR)&gadget_drawer)    /* DRAWER: */
  584.            {
  585.              /* The user has entered something new in the drawer: */
  586.              new_drawer();
  587.              break;
  588.            }
  589.  
  590.            if(address == (APTR)&gadget_extension)    /* EXTENSION: */
  591.            {
  592.              /* If extension used, text "Ext:" is highlighted */
  593.              if(*extension_name != '\0')
  594.                text_extension.FrontPen=3; /* Orange. (Normal WB colour) */
  595.              else
  596.                text_extension.FrontPen=1; /* White. (Normal WB colour) */
  597.  
  598.              /* Show the user the colour change: */
  599.              RefreshGadgets(&gadget_extension, file_window, NULL);
  600.  
  601.              /* Start again to diplay the files, using a new extension. */
  602.              new_drawer();
  603.              break;
  604.            }
  605.  
  606.            if(address == (APTR)&gadget_parent)        /* PARENT: "<" */
  607.            {
  608.              parent();
  609.              break;
  610.            }
  611.  
  612.            if(address == (APTR)&gadget_proportional)    /* PROPORTIONAL */
  613.            {
  614.              /* Proportional gadget released, update display */
  615.              fix_display=TRUE;
  616.              break;
  617.            }
  618.  
  619.            if(address == (APTR)&gadget_option)    /* OPTION */
  620.            {
  621.              connect_dir_file(total_file_name);
  622.              working=FALSE;
  623.              operation=OPTION;
  624.              break;
  625.            }
  626.  
  627.            if(address == (APTR)&gadget_help)    /* HELP */
  628.            {
  629.              connect_dir_file(total_file_name);
  630.              working=FALSE;
  631.              operation=HELP;
  632.              break;
  633.            }
  634.  
  635.       }
  636.     }
  637.  
  638.     if(fix_display)    /* Do we need to update the file display? */
  639.     {
  640.       fix_display=FALSE;
  641.  
  642.       /* Which file should we start to show in the display? */
  643.       if(file_count > 8)
  644.         position=(int) prop_info.VertPot/(float) 0xFFFF*(file_count-8);
  645.       else
  646.         position=0;
  647.  
  648.       /* List the files: (Starting with position) */
  649.       display_list(position);
  650.     }
  651.  
  652.  
  653.     if(more_files)
  654.     {
  655.       /* Are there more files/dirtectories left to be collected? */    
  656.       if(ExNext(lock, file_info))
  657.       {
  658.         /* List the file/directory if it is: */
  659.         /* 1. A file which has the right extension. */
  660.         /* 2. A directory. */
  661. /*      if(stricmp(extension_name, (file_info->fib_FileName+*/
  662. /*                changed "stricmp" to "strcmp" */
  663.         if(strcmp(extension_name, (file_info->fib_FileName+
  664.            strlen(file_info->fib_FileName)-strlen(extension_name)))==0 ||
  665.            directory(file_info) )
  666.         {
  667.           /* Is this the first file/directory? */
  668.           if(first_file)
  669.           {
  670.             /* first_pointer will point at the first file in our list: */
  671.             first_pointer=(struct file_info *) save_file_info(file_info);
  672.             
  673.             if(first_pointer != NULL)
  674.             {
  675.               /* There are no more elements (for the moment) in our list: */ 
  676.               first_pointer->next=NULL; 
  677.               first_file=FALSE;
  678.             }
  679.             file_count=1;
  680.             position=1;
  681.           }
  682.           else
  683.           {
  684.             /* save_file_info will return a pointer to the allocated */
  685.             /* structure: */
  686.             pointer=(struct file_info *) save_file_info(file_info);
  687.             
  688.             /* If space allocated for file, add it to list */
  689.             if(pointer !=NULL)
  690.             {
  691.               /* Put new structure into list: */
  692.               put_in(first_pointer, pointer);       
  693.               file_count++;
  694.             }
  695.           }
  696.         
  697.           /* If > 8 files/directories, modify proportional gadget */
  698.           if(file_count > 8)
  699.           {
  700.             ModifyProp
  701.             (
  702.               &gadget_proportional,       /* PropGadget */
  703.               file_window,                /* Pointer */
  704.               NULL,                       /* Requester */
  705.               prop_info.Flags,            /* Flags */
  706.               0,                          /* HorizPot */
  707.               prop_info.VertPot,          /* VertPot */
  708.               0,                          /* HorizBody */
  709.               (ULONG) 0xFFFF*8/file_count /* VerBody */
  710.             );            
  711.             position=(int) prop_info.VertPot/(float) 0xFFFF*(file_count-8);
  712.           }
  713.           else
  714.            position=0;
  715.  
  716.  
  717.           /* List all the files: */
  718.           display_list(position);
  719.         }
  720.       }
  721.       else
  722.       {
  723.         /* ExNext() failed: */
  724.         
  725.         more_files=FALSE; /* Do not try to list any more files. */
  726.  
  727.         /* Check what went wrong: */
  728.         /* If error msg NOT "ERROR_NO_MORE_ENTRIES", serious reading error*/
  729.         if(IoErr() != ERROR_NO_MORE_ENTRIES)
  730.         {
  731.           request_ok("FileWindow--ERROR reading file/directory!");
  732.         }
  733.       }
  734.     }
  735.   } while(working);
  736.  
  737.   /* Clean up and leave: */
  738.  
  739.   /* This will clear the IDCMP port: */
  740.   while( (my_gadget_message = (struct IntuiMessage *)
  741.            GetMsg(file_window->UserPort)) )
  742.   {
  743.     ReplyMsg((struct Message *)my_gadget_message);
  744.   }
  745.  
  746.   /* Deallocate the memory we have dynamically allocated: */ 
  747.   deallocate_file_info();
  748.  
  749.   /* If we have "locked" a file/directory, "unlock" it: */
  750.   if(file_lock)
  751.   {
  752.     UnLock(lock);
  753.     file_lock=FALSE;
  754.   }
  755.   
  756.   /* Deallocate FileInfoBlock: */
  757.   if(file_info) FreeMem(file_info, sizeof(struct FileInfoBlock));
  758.  
  759.   /* If we have successfully opened the file_window, we close it: */
  760.   if(file_window)
  761.     CloseWindow(file_window);
  762.   
  763.   /* Leave with a message: */
  764.   return(operation);
  765. }
  766.  
  767.         /* Deallocate the memory we have dynamically allocated: */ 
  768. void deallocate_file_info()
  769. {
  770.   struct file_info *pointer, *temp_pointer;
  771.  
  772.   /* Does the first pointer point to an allocated structure? */   
  773.   if(first_pointer)
  774.   {
  775.     /* Save the address of the next structure: */
  776.     pointer=first_pointer->next;
  777.     
  778.     /* Deallocate the first structure: */
  779.     FreeMem( first_pointer, sizeof(struct file_info));
  780.  
  781.     /* As long as pointer points to an allocated structure: */
  782.     while(pointer)
  783.     {
  784.       /* Save the address of the next structure: */    
  785.       temp_pointer=pointer->next;
  786.       
  787.       FreeMem( pointer, sizeof(struct file_info));
  788.       pointer=temp_pointer;
  789.     }
  790.   }
  791.   
  792.   /* Clear first_pointer: */
  793.   first_pointer=NULL;
  794.  
  795.   /* Next time we try to list the files, we start with the first_file: */
  796.   first_file=TRUE;
  797. }
  798.  
  799.  
  800. /* Allocate memory for the new file/directory, and fills the structure */
  801. /* with information. (name of the object, and if it is a directory.)   */
  802. /* Returns a memory pointer to the allocated structure, or NULL.       */
  803. APTR save_file_info(info)
  804. struct FileInfoBlock *info;
  805. {
  806.   struct file_info *pointer;
  807.  
  808.   if((pointer=(struct file_info *)
  809.     AllocMem(sizeof(struct file_info), MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  810.   {
  811.     /* We could NOT allocate memory for the structure! */
  812.     request_ok("FileWindow--NOT enough memory!"); /* Inform the user. */
  813.     more_files=FALSE; /* Do not list any more files/directories. */
  814.     return(NULL);
  815.   }
  816.   else
  817.   {
  818.     /* If the file/directory name is not too long, we copy it into the */
  819.     /* new stucture: */
  820.     if(strlen(info->fib_FileName) < 28)
  821.       strcpy(pointer->name, info->fib_FileName);
  822.     else
  823.     {
  824.       /* The file/directory name is too long! */
  825.       /* Inform the user: */
  826.       
  827.       if( directory(info))
  828.         request_ok("FileWindow--Directory name too long!");/* Directory*/
  829.       else    
  830.         request_ok("FileWindow--File name too long!"); /* File. */
  831.  
  832.       /* Deallocate the structure: */
  833.       FreeMem( pointer, sizeof(struct file_info));
  834.       return(NULL);
  835.     }
  836.  
  837.     /* Is it a file or a directory? */
  838.     if( directory(info))
  839.       pointer->directory=TRUE; /* It is a directory. */
  840.     else    
  841.       pointer->directory=FALSE; /* It is a file. */
  842.   }
  843.   
  844.   /* Return the address of the allocated structure: */
  845.   return( (APTR) pointer);
  846. }
  847.  
  848.  
  849. /* Will check a FileInfoBlock if it is a file or a directory. */
  850. /* Return TRUE if it is a directory, FALSE if it is a file.   */
  851. BOOL directory(info)
  852. struct FileInfoBlock *info;
  853. {
  854.   if(info->fib_DirEntryType < 0)
  855.     return(FALSE);
  856.   else
  857.     return(TRUE);
  858. }
  859.  
  860.  
  861. /* Put the new structure into the dynamically allocated list at the */
  862. /* right place (sorted alphabetically, directories first):          */
  863. void put_in(a_pointer, pointer)
  864. struct file_info *a_pointer, *pointer;
  865. {
  866.   struct file_info *old_pointer=NULL;
  867.  
  868.   /* Move slowly down the list and try to fit in the structure: */
  869.   while( a_pointer && file_comp(a_pointer->name, pointer->name) )
  870.   {
  871.     old_pointer=a_pointer;
  872.     a_pointer=a_pointer->next;
  873.   }
  874.  
  875.   if(a_pointer)
  876.   {
  877.     if(old_pointer)
  878.     {
  879.       /* Put the structure into the list: */
  880.       pointer->next=old_pointer->next;
  881.       old_pointer->next=pointer;
  882.     }
  883.     else
  884.     {
  885.       /* First in the list! */
  886.       pointer->next=first_pointer;
  887.       first_pointer=pointer;
  888.     }
  889.   }
  890.   else
  891.   {
  892.     /* Last int the list: */
  893.     old_pointer->next=pointer;
  894.     pointer->next=NULL;
  895.   }
  896. }
  897.  
  898.  
  899. /* This function will return TRUE if the first pointer (a_pointer) */
  900. /* points to a file structure which should come before the second  */
  901. /* pointers file structure.                                        */
  902. /* ORDER:  1. DIRECTORIES  alpha sort.  2. FILES   alpha sort. */
  903.  
  904. BOOL file_comp(a_pointer, pointer)
  905. struct file_info *a_pointer, *pointer;
  906. {
  907.  char name1[28], name2[28], *cp1, *cp2;
  908.  
  909.   if(a_pointer->directory == FALSE && pointer->directory)
  910.     return(FALSE);
  911.     
  912.   if(a_pointer->directory == pointer->directory)
  913.   {
  914. /*  if(stricmp(a_pointer->name, pointer->name) <= 0 )*/
  915. /*            changed "stricmp" to "strcmp".  But to function like stricmp, */
  916. /* we need to convert the names to lower case for the sort. */
  917.  
  918.     /* Convert first name to lower case in name1 */
  919.     for (cp1=a_pointer->name, cp2=name1; *cp2++ = igncase(*cp1); cp1++) ;
  920.  
  921.     /* Convert second name to lower case in name2 */
  922.     for (cp1=pointer->name, cp2=name2; *cp2++ = igncase(*cp1); cp1++) ;
  923.  
  924.     if(strcmp(name1, name2) <= 0 )
  925.       return(TRUE);
  926.     else
  927.       return(FALSE);
  928.   } 
  929.   return(TRUE);
  930. }
  931.  
  932.  
  933. /* Give this function a string and a character, and it will return a */
  934. /* pointer to the right most occurance character in you string which */
  935. /* match your character.                                             */
  936. STRPTR right_pos(string, sign)
  937. STRPTR string;
  938. char sign;
  939. {
  940.   STRPTR start_pos;
  941.   
  942.   start_pos=string;
  943.   
  944.   /* Go to the end: */
  945.   while(*string != '\0')
  946.     string++;
  947.  
  948.   /* Start to go backwards and check teh string: */
  949.   while(*string != sign && string > start_pos)
  950.     string--;
  951.     
  952.   if(*string==sign)
  953.     return(string); /* We have found a matching character. */
  954.  
  955.   return(NULL); /* We could not find a matching character. */
  956. }
  957.  
  958.  
  959. /* This function will change to a new device, for example df0:. */
  960. /* Does not return anything.                                    */
  961. void change_device(device)
  962. STRPTR device;
  963. {
  964.   strcpy(drawer_name, device); /* Change the drawer string. */
  965.  
  966.   adjust_string_gadgets(); /* Adjust the string gadgets. */
  967.  
  968.   new_drawer(); /* Start to show us the new files/directories */
  969. }
  970.  
  971.  
  972. /* When the user or the program has changet the drawer string, this      */
  973. /* function is called, and will do what is necessary to start to collect */
  974. /* the new files/directories from the disk.                              */
  975. /* Returns TRUE if everything is OK, and FALSE if something went wrong.  */
  976. BOOL new_drawer()
  977. {
  978.   STRPTR string_pointer;
  979.  
  980.   /* Unlock: */
  981.   if(file_lock)
  982.   {
  983.     UnLock(lock);
  984.     file_lock=FALSE;
  985.   }
  986.  
  987.   /* Deallocate the memory we have dynamically allocated: */ 
  988.   deallocate_file_info();
  989.  
  990.   /* Change the proportianal gadget: */
  991.   ModifyProp
  992.   (
  993.     &gadget_proportional, /* PropGadget */
  994.     file_window,          /* Pointer */
  995.     NULL,                 /* Requester */
  996.     prop_info.Flags,      /* Flags */
  997.     0,                    /* HorizPot */
  998.     0,                    /* VertPot */
  999.     0,                    /* HorizBody */
  1000.     (ULONG) 0xFFFF        /* VerBody */
  1001.   );
  1002.  
  1003.   /* Clear the display: */
  1004.   display_list(0);
  1005.  
  1006.   more_files=FALSE;
  1007.  
  1008.   /* Try to "lock" the file/directory: */
  1009.   if((lock=Lock(drawer_name, ACCESS_READ))==NULL)
  1010.   {
  1011.     /* We could NOT lock the file/directory/device! */
  1012.     /* Inform the user: */
  1013.     string_pointer=drawer_name+strlen(drawer_name)-1;
  1014.     if(*string_pointer==':')
  1015.       request_ok("FileWindow--Device NOT found!");
  1016.     else
  1017.       request_ok("FileWindow--Device/Directory NOT found!");
  1018.  
  1019.     return(FALSE); /* ERROR */
  1020.   }
  1021.   else
  1022.   {
  1023.     /* We "locked" the file/directory! */
  1024.     file_lock=TRUE;
  1025.   }
  1026.  
  1027.   /* Now try to get some information from the file/directory: */
  1028.   if((Examine(lock, file_info))==NULL)
  1029.   {
  1030.     /* We could NOT examine the file/directory! */
  1031.  
  1032.     request_ok("FileWindow--ERROR reading file/directory!");
  1033.  
  1034.     return(FALSE); /* ERROR */
  1035.   }
  1036.  
  1037.   /* Is it a directory or a file? */
  1038.   if(directory(file_info))
  1039.   {
  1040.     /* It is a directory! */
  1041.  
  1042.     /* Since it is a directory, we will look for more files: */
  1043.     more_files=TRUE;
  1044.   }
  1045.   else
  1046.   {
  1047.     /* It is a file! */
  1048.     request_ok("FileWindow--NOT a valid directory name!");
  1049.     return(FALSE);
  1050.   }  
  1051.   return(TRUE);
  1052. }
  1053.  
  1054.  
  1055. /* The function parent() will try to go backwards one step in the */
  1056. /* directory path.                                                */
  1057. /* Does not return anything.                                      */
  1058. void parent()
  1059. {
  1060.   STRPTR string_pointer;
  1061.  
  1062.   /* Separate the last directory from the path: */
  1063.   if(string_pointer=right_pos(drawer_name, '/'))
  1064.   {
  1065.     /* Take away the last directory: */
  1066.     *string_pointer='\0';
  1067.   }
  1068.   else
  1069.   {
  1070.     if(string_pointer=right_pos(drawer_name, ':'))
  1071.     {
  1072.       /* Take away the last directory: */
  1073.       /* Only the device ("df0:" for example) left: */
  1074.       *(string_pointer+1)='\0';
  1075.     }
  1076.     else
  1077.     {
  1078.       /* Strange drawer_name, clear it: */
  1079.       *drawer_name='\0';
  1080.     }
  1081.   }
  1082.  
  1083.   /* Since we have messed around with the string gadgets, adjust them: */
  1084.   adjust_string_gadgets();
  1085.   
  1086.   /* Start to show the user the files etc in the new directory: */
  1087.   new_drawer();
  1088. }
  1089.  
  1090.  
  1091. /* You give this function a pointer to an error string, and it will open */
  1092. /* a simple requester displaying the message. The requester will go away */
  1093. /* first when the user has selected the button "OK".                     */
  1094. /* Does not return anything.                                             */
  1095. void request_ok(message)
  1096. STRPTR message;
  1097. {
  1098.   text_request.IText=message;
  1099.   
  1100.   AutoRequest
  1101.   (
  1102.     file_window,   /* Window */
  1103.     &text_request, /* BodyText */
  1104.     NULL,          /* PositiveText nothing */
  1105.     &ok_request,   /* NegativeText OK */
  1106.     NULL,          /* PositiveFlags */
  1107.     NULL,          /* NegativeFlags */
  1108.     320,           /* Width */
  1109.     72             /* Height */
  1110.   );
  1111. }
  1112.  
  1113.  
  1114. /* This function will display the files etc which are inside the */
  1115. /* directory, starting with the file number start_pos.           */
  1116. /* Does not return anything.                                     */
  1117. void display_list(start_pos)
  1118. int start_pos;
  1119. {
  1120.   struct file_info *pointer;
  1121.   int pos, temp1;
  1122.                   /* 123456789012345678901234567890123 */
  1123.   char empty_name[]="                                 ";
  1124.   STRPTR string_pointer;
  1125.   BOOL clear;
  1126.   
  1127.   pos=0;
  1128.   
  1129.   /* Does it exist any files at all? */
  1130.   if(first_pointer)
  1131.   {
  1132.     pointer=first_pointer;
  1133.  
  1134.     /* Go through the list until you have found the file/directory */
  1135.     /* which should be shown first:                                */
  1136.     while(pointer && pos < start_pos)
  1137.     {
  1138.       pos++;
  1139.       pointer=pointer->next;
  1140.     }
  1141.     
  1142.     /* Try to show the eight files: */
  1143.     pos=0;
  1144.     while(pointer && pos < 8)
  1145.     {
  1146.       strcpy(display_text[pos], pointer->name);
  1147.       
  1148.       clear=FALSE;
  1149.       temp1=0;
  1150.       string_pointer=display_text[pos];
  1151.  
  1152.       if(pointer->directory)
  1153.       {
  1154.         /* It is a directory: */
  1155.         text_list[pos].FrontPen=3; /* Highlight it. */
  1156.  
  1157.         /* Clear everything after the name, and add the string "(Dir)". */
  1158.         while(temp1 < 28)
  1159.         {
  1160.           if(*string_pointer=='\0')
  1161.             clear=TRUE;
  1162.           if(clear)
  1163.             *string_pointer=' ';
  1164.           string_pointer++;
  1165.           temp1++;
  1166.         }
  1167.         *string_pointer='\0';
  1168.         strcat(display_text[pos], "(Dir)");
  1169.       }
  1170.       else
  1171.       {
  1172.         /* It is a file: */
  1173.         text_list[pos].FrontPen=1; /* Normal colour. */
  1174.  
  1175.         /* Clear everything after the name: */
  1176.         while(temp1 < 33)
  1177.         {
  1178.           if(*string_pointer=='\0')
  1179.             clear=TRUE;
  1180.           if(clear)
  1181.             *string_pointer=' ';
  1182.           string_pointer++;
  1183.           temp1++;
  1184.         }
  1185.         *string_pointer='\0';
  1186.       }      
  1187.       pos++;
  1188.       pointer=pointer->next; /* Next. */
  1189.     }
  1190.   }
  1191.  
  1192.   /* If there are less than eight files, show clear the rest of the */
  1193.   /* display: */
  1194.   while(pos < 8)
  1195.   {
  1196.     strcpy(display_text[pos], empty_name);
  1197.     pos++;
  1198.   }
  1199.   
  1200.   /* Show the user the new display: */
  1201.   PrintIText(file_window->RPort, text_list, 13+3, 53+1);
  1202. }
  1203.  
  1204.  
  1205. /* The user has selected a file or a directory. If it is a file put it */
  1206. /* into the file string, otherwise put it into the drawer string.      */
  1207. /* Returns TRUE if everything went OK, FALSE if there was a problem.   */
  1208. BOOL pick_file(file_pos)
  1209. int file_pos;
  1210. {
  1211.   struct file_info *pointer=NULL;
  1212.   STRPTR string_pointer;
  1213.   int pos=0;
  1214.   
  1215.   /* Go through the allocated list untill we find the file/directory: */
  1216.   if(first_pointer)
  1217.   {
  1218.     pointer=first_pointer;
  1219.     
  1220.     while(pointer && pos < file_pos)
  1221.     {
  1222.       pos++;
  1223.       pointer=pointer->next;
  1224.     }
  1225.   }
  1226.  
  1227.   /* Have we found the file/directory? */
  1228.   if(pointer)
  1229.   {
  1230.     if(pointer->directory)
  1231.     {
  1232.       /* It is a directory! */
  1233.       
  1234.       /* Is the drawer_name string long enough? */
  1235.       /* (+2: 1 for the NULL ('\0') character, 1 for the '\' character) */
  1236.       if((strlen(pointer->name)+strlen(drawer_name)+2) <= DRAWER_LENGTH)
  1237.       {
  1238.         /* YES!, there is enough room for it. */
  1239.         string_pointer=drawer_name+strlen(drawer_name)-1;
  1240.         if(*string_pointer==':'  || *string_pointer=='\0' )
  1241.           strcat(drawer_name, pointer->name);
  1242.         else
  1243.         {
  1244.           /* We need to add a '/' before we can add the directory. */
  1245.           strcat(drawer_name, "/");
  1246.           strcat(drawer_name, pointer->name);
  1247.         }
  1248.         
  1249.         /* Adjust the string gadgets: */
  1250.         adjust_string_gadgets();
  1251.       }
  1252.       else
  1253.       {
  1254.         /* The drawer_name is NOT big enough! */
  1255.         request_ok("FileWindow--Too long drawer string");
  1256.         return(FALSE); /* ERROR */
  1257.       }
  1258.       new_drawer();
  1259.       return(TRUE); /* OK */
  1260.     }
  1261.     else
  1262.     {
  1263.       /* It is a File! */
  1264.       /* Is the file_name string long enough? */
  1265.       /* (+1 for the NULL ('\0') character.) */
  1266.       if((strlen(pointer->name)+1) <= FILE_LENGTH)
  1267.       {
  1268.         strcpy(file_name, pointer->name);
  1269.         adjust_string_gadgets();
  1270.       }
  1271.       else
  1272.       {
  1273.         /* The file_name is NOT big enough! */
  1274.         request_ok("FileWindow--File name too long!");
  1275.         return(FALSE); /* ERROR */
  1276.       }
  1277.       return(TRUE); /* OK */
  1278.     }
  1279.   }
  1280. }
  1281.  
  1282.  
  1283. /* Adjust the string gadgets, so the user can */
  1284. /* at least see the last 28/22 characters.    */
  1285. /* Does not return anything.                  */
  1286. void adjust_string_gadgets()
  1287. {
  1288.   int length;
  1289.  
  1290.   length=strlen(file_name);        
  1291.  
  1292.   if(length > 28)
  1293.     string_file.DispPos=length-28;
  1294.   else
  1295.     string_file.DispPos=0;
  1296.  
  1297.   string_file.BufferPos=string_file.DispPos;
  1298.  
  1299.   length=strlen(drawer_name);        
  1300.  
  1301.   if(length > 22)
  1302.     string_drawer.DispPos=length-22;
  1303.   else
  1304.     string_drawer.DispPos=0;
  1305.  
  1306.   string_drawer.BufferPos=string_drawer.DispPos;
  1307.  
  1308.   /* Display the changes. */
  1309.   RefreshGadgets(&gadget_file, file_window, NULL);
  1310. }
  1311.  
  1312.  
  1313. /* Returns TRUE if there exist a file name, otherwise FALSE. */
  1314. BOOL last_check(name)
  1315. STRPTR name;
  1316. {
  1317.   if(*file_name == '\0')
  1318.   {
  1319.     /* No file name! */
  1320.     request_ok("FileWindow--NO filename selected!");
  1321.     return(FALSE);
  1322.   }
  1323.   else
  1324.   {
  1325.     /* Change the total_file_name. Drawer + File. */
  1326.     connect_dir_file(name);
  1327.   }
  1328.   return(TRUE);
  1329. }
  1330.  
  1331.  
  1332. /* This function will connect the drawer string with the file string. */
  1333. /* Does not return anything.                                          */
  1334. void connect_dir_file(name)
  1335. STRPTR name;
  1336. {
  1337.   STRPTR string_pointer;
  1338.   
  1339.   strcpy(name, drawer_name); /* Copy the drawer string into name. */
  1340.  
  1341.   /* Does it exist a file name? */
  1342.   if(*file_name != '\0')
  1343.   {
  1344.     /* Yes! */
  1345.     string_pointer=drawer_name+strlen(drawer_name)-1;
  1346.     if(*string_pointer==':'  || *string_pointer=='\0' )
  1347.     {
  1348.       strcat(name, file_name); /* Add the file name. */
  1349.     }
  1350.     else
  1351.     {
  1352.       strcat(name, "/"); /* Add a '\'. */
  1353.       strcat(name, file_name); /* Add the file name. */
  1354.     }
  1355.   }
  1356. }    /* THE END */
  1357.